package MeteoCal.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @authors Guttadoro, Iommazzo, Saullo
 */
@Entity
@Table(name = "invitation")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Invitation.findAll", query = "SELECT i FROM Invitation i"),
    @NamedQuery(name = "Invitation.findByIdUser", query = "SELECT i FROM Invitation i WHERE i.invitationPK.idUser = :idUser"),
    @NamedQuery(name = "Invitation.findByIdEvent", query = "SELECT i FROM Invitation i WHERE i.invitationPK.idEvent = :idEvent"),
    @NamedQuery(name = "Invitation.findByDateTimeRequest", query = "SELECT i FROM Invitation i WHERE i.dateTimeRequest = :dateTimeRequest"),
    @NamedQuery(name = "Invitation.findByDateTimeResponse", query = "SELECT i FROM Invitation i WHERE i.dateTimeResponse = :dateTimeResponse"),
    @NamedQuery(name = "Invitation.findByResponse", query = "SELECT i FROM Invitation i WHERE i.response = :response"),
    @NamedQuery(name = Invitation.findByResponseAndEvent, query = "SELECT i FROM Invitation i WHERE i.response = :response AND i.invitationPK.idEvent = :idEvent" ),    
    @NamedQuery(name = Invitation.findByResponseAndUser, query = "SELECT i FROM Invitation i WHERE i.response = :response AND i.invitationPK.idUser = :idUser" )})
public class Invitation implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected InvitationPK invitationPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Date_TimeRequest")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateTimeRequest;
    @Column(name = "Date_TimeResponse")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateTimeResponse;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 5)
    @Column(name = "Response")
    private String response;
    public static final String findByResponseAndUser = "Invitation.findByResponseAndUser";
    public static final String findByResponseAndEvent = "Invitation.findByResponseAndEvent";

    

    @JoinColumn(name = "idEvent", referencedColumnName = "idEvent", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Event event;
    @JoinColumn(name = "idUser", referencedColumnName = "Email", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private User user;

    public Invitation() {
    }

    public Invitation(InvitationPK invitationPK) {
        this.invitationPK = invitationPK;
    }

    public Invitation(InvitationPK invitationPK, Date dateTimeRequest, String response) {
        this.invitationPK = invitationPK;
        this.dateTimeRequest = dateTimeRequest;
        this.response = response;
    }

    public Invitation(String idUser, int idEvent) {
        this.invitationPK = new InvitationPK(idUser, idEvent);
    }

    public InvitationPK getInvitationPK() {
        return invitationPK;
    }

    public void setInvitationPK(InvitationPK invitationPK) {
        this.invitationPK = invitationPK;
    }

    public Date getDateTimeRequest() {
        return dateTimeRequest;
    }

    public void setDateTimeRequest(Date dateTimeRequest) {
        this.dateTimeRequest = dateTimeRequest;
    }

    public Date getDateTimeResponse() {
        return dateTimeResponse;
    }

    public void setDateTimeResponse(Date dateTimeResponse) {
        this.dateTimeResponse = dateTimeResponse;
    }

    public String getResponse() {
        return response;
    }

    public void setResponse(String response) {
        this.response = response;
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (invitationPK != null ? invitationPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Invitation)) {
            return false;
        }
        Invitation other = (Invitation) object;
        if ((this.invitationPK == null && other.invitationPK != null) || (this.invitationPK != null && !this.invitationPK.equals(other.invitationPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "MeteoCal.entity.Invitation[ invitationPK=" + invitationPK + " ]";
    }
    
}















